﻿using Architecture.Domain.Services.Interface;
using Architecture.Domian.Common;
using Architecture.Domian.DTO;
using Architecture.Domian.Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Architecture.Api.Controllers
{
    /// <summary>
    /// 用户管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class UserController : ControllerBase
    {
        private readonly IUserService _userService;

        public UserController(IUserService userService)
        {
            _userService = userService;
        }

        [HttpPost]
        public async Task<int> UserInsert(UserInfo user)
        {
            var res = _userService.UserInsert(user);
            return await res;
        }

        [HttpGet]
        public async Task<PageResult<UserInfoDTO>> GetUserInfoList(int size, int index)
        {
            var res = _userService.GetPage(size, index);
            return await res;
        }

        [HttpGet]
        public async Task<UserInfo> GetUserInfoByUserId(int userId)
        {
            var res = _userService.GetUserInfoByUserId(userId);
            return await res;
        }

        [HttpPut]
        public async Task<int> LogicDelete(int userId)
        {
            var res = _userService.LogicDelete(userId);
            return await res;
        }

        [HttpPut]
        public async Task<int> UpdateUserInfo(UserInfo user)
        {
            var res = _userService.UpdateUserInfo(user);
            return await res;
        }
    }
}
